package com.sixth.volunteerservicesystem.Service.impl;

import com.sixth.volunteerservicesystem.Service.IBackendProjectService;
import com.sixth.volunteerservicesystem.domain.CURDResult;
import com.sixth.volunteerservicesystem.domain.PageResult;
import com.sixth.volunteerservicesystem.domain.Project;
import com.sixth.volunteerservicesystem.mapper.BackendProjectMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

@Service
public class BackendProjectServiceImpl implements IBackendProjectService {
    @Autowired(required = false)
    BackendProjectMapper backendProjectMapper;

    @Override
    public PageResult<Project> findProjectPageResult(Project condition, int page, int pageSize) {
        System.out.println("=================Controller执行=========================");
        PageResult<Project> result = new PageResult<>();
        result.setCode(0);

        HashMap<String, Object> params = new HashMap<>();
        params.put("start",(page-1)*pageSize);
        params.put("pageSize",pageSize);

        // 获取总记录数
        int total = backendProjectMapper.findCountByMap(params);
        result.setCount(total);
        List<Project> list = backendProjectMapper.findListByMap(params);
        result.setData(list);


        return result;
    }

    @Override
    public CURDResult projectsave(Project project) {
        return null;
    }

    @Override
    public Project findProjectById(String formId) {
        return backendProjectMapper.findByformId(formId);
    }
}
